# frozen_string_literal: true

# class for tasks
class BlockChain
  include Mongoid::Document
  include Mongoid::Timestamps
  include Db::Operations
  include Db::Cacheable
  field :exchange, type: String
  field :asset_name, type: String
  field :price, type: Integer, default: 0 # 0: draft; 1:planned
  field :is_mock, type: Boolean, default: false

  # after_create :send_create_msg
  # after_update :send_update_msg
  # after_destroy :send_destroy_msg

  def self.sendprice
    # redis = Redis.new
    data = { exchange: 'huobi', asset_name: 'btc', price: '10023' }
    front_action = { 'namespace': 'chart',
                     'mutation': 'updatePrice' }
    redis.publish(:broadcast, front_action.merge!(data).to_json)
  end
end
